package com.zzh.controller;

import com.zzh.common.AccessLimit;
import com.zzh.entity.Result;
import com.zzh.entity.requestDto.LoginDto;
import com.zzh.entity.requestDto.SendDto;
import com.zzh.service.login.LoginAboutService;
import org.springframework.web.bind.annotation.*;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Map;

/**
 * @author wenrouyue
 * @FileName: UserController
 * @description
 * @create 2023/2/11-18:56
 **/


@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private LoginAboutService loginAboutService;

    @AccessLimit(seconds = 30, maxCount = 10)
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public Result<Map<String, String>> login(@Valid @RequestBody LoginDto loginDto,HttpServletRequest request) {
        return loginAboutService.userLogin(loginDto,request);
    }

    @AccessLimit(seconds = 30, maxCount = 10)
    @GetMapping(value = "/logoutService")
    public Result<String> logoutService() {
        return loginAboutService.logoutService();
    }


    @RequestMapping(value = "/send", method = RequestMethod.POST)
    @AccessLimit(maxCount = 1)
    public Result<String> send(@Valid @RequestBody LoginDto loginDto) {
        return loginAboutService.send(loginDto);
    }

    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @AccessLimit(seconds = 86400, maxCount = 3)
    public Result<String> register(@Valid @RequestBody LoginDto loginDto, HttpServletRequest request) {
        return loginAboutService.register(loginDto, request);
    }

    @RequestMapping(value = "/sendMsg", method = RequestMethod.POST)
    @AccessLimit(maxCount = 10)
    public Result<String> sendMsg(@Valid @RequestBody SendDto send) {
        return loginAboutService.sendMsg(send);
    }
}
